<?php

/* 
 * 商家模型
 * @author wyb
 */
namespace Qwadmin\Model;
class SmsApiModel extends ApiModel {
   
   public $url='http://sapi.253.com/msg/HttpBatchSendSM'; 
   public $account='vip_hjh';
   public $pswd='Tch123456';
   ///http://sapi.253.com/msg/index.jsp
   ///管理url
   function __construct()
   {   
      header('Content-Type:text/html;charset=utf-8');
	  $this->url='http://sapi.253.com/msg/HttpBatchSendSM';
   }
   function test()
   {
	   $this->send('18992854126',"验证码：434328  更多优质产品查看 http://t.cn/RIy1iW9 。");
	   
   }
   public function send($tel,$data)
   {   
        $this->__construct();    
   	    $post_data = array();
        $post_data['account'] = $this->account;
        $post_data['pswd'] = $this->pswd;
        $post_data['mobile'] =$tel;
        $post_data['msg']=$data;
        $post_data['needstatus']='true';
        $o="";
        var_dump($post_data);
        echo $this->url;
		echo "<br>";
		 
	    $statusCode=$this->http_request($this->url,http_build_query($post_data));
		
		var_dump($statusCode);
		

   }
   
   private function curlPost($url,$postFields){
		$postFields = http_build_query($postFields);
		$ch = curl_init ();
		curl_setopt ( $ch, CURLOPT_POST, 1 );
		curl_setopt ( $ch, CURLOPT_HEADER, 0 );
		curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
		curl_setopt ( $ch, CURLOPT_URL, $url );
		curl_setopt ( $ch, CURLOPT_POSTFIELDS, $postFields );
		$result = curl_exec ( $ch );
		curl_close ( $ch );
		return $result;
	}
 
function http_request($url,$data = null){
	
	if(function_exists('curl_init')){
		$curl = curl_init();
	    curl_setopt($curl, CURLOPT_URL, $url);
	   
	    if (!empty($data)){
	        curl_setopt($curl, CURLOPT_POST, 1);
	        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
	    }
	    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	    $output = curl_exec($curl);
	    curl_close($curl);
		
	    var_dump($output);
		$result=preg_split("/[,\r\n]/",$output);

		if($result[1]==0){
			  return "curl send success";
		}else{
			  return "curl error".$result[1];
		}
	}elseif(function_exists('file_get_contents')){
		
		$output=file_get_contents($url.$data);
		$result=preg_split("/[,\r\n]/",$output);
	
		if($result[1]==0){
			  return "success";
		}else{
			  return "error".$result[1];
		}
		
		
	}else{
		return false;
	} 
	
}
}

